<?php 
defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$tpl=new TemplatePower("skin/showcatmenu.htm");
$tpl->prepare();
$lang=$_REQUEST['lang'];
$type_menu=$_REQUEST['type_menu'];
$type_request=array("news","products","home","info","contact","gallery","logo");

$type_replace=array("cat","catpd","home","catif","contact","sitemap","catpt","catlg");

$type_cat=array("id_cat","id_catpd","home","id_catif","contact","sitemap","id_catpt","id_catlg");

$type_data=str_replace($type_request,$type_replace,$type_menu);

$id_cat=str_replace($type_replace,$type_cat,$type_data);

switch($type_menu){
	case "news":
		$id_cat='id_cat';
		break;
	case "products":
		$id_cat='id_catpd';
		break;
	case "info":
		$id_cat='id_catif';
		break;
	case "gallery":
		$id_cat='id_catpt';
		break;
	case "logo":
		$id_cat='id_catlg';
		break;
	default:
		$id_cat='id_cat';
}

switch($type_menu){
	case "news":
		$type_data='cat';
		break;
	case "products":
		$type_data='catpd';
		break;
	case "info":
		$type_data='catif';
		break;
	case "gallery":
		$type_data='catpt';
		break;
	case "logo":
		$type_data='catlg';
		break;
	default:
		$type_data='cat';
}

if($_REQUEST['type_menu']=='home' || $_REQUEST['type_menu']=='contact'){
	switch($type_menu){
		case "home":
			Get_Link_Static('trang-chu',"Trang chủ");
			break;
		case "contact":
			Get_Link_Static('lien-he',"Liên hệ");
			break;
		case "sitemap":
			Get_Link_Static('sitemap',"Site map");
			break;
	}
}else{
	Get_Cat_Show_Menu($type_data,$id_cat);
}

$tpl->printToScreen();
function Get_Link_Static($page,$nameshow){
	global $tpl,$site_address, $ex;
	$tpl->newBlock("staticlink");
	$tpl->assign("link",$page.'.html');
	$tpl->assign("name",$nameshow);
}

function Get_Cat_Show_Menu($cat='news',$id_cat='id_cat'){
	global $DB,$tpl, $linkfirst,$site_address;

	$idc=intval($_REQUEST['idc']);
	$sql="SELECT * FROM $cat WHERE active=1 AND parentid=0 ORDER BY thu_tu DESC, name ASC";
	$db=$DB->query($sql);

	while($rs=mysql_fetch_array($db)){
		$tpl->newBlock("showcatmenu");
		$tpl->assign("name",$rs['name']);
		$tpl->assign("id_cat",$rs[$id_cat]);
		$tpl->assign("link",$rs['url']);
		if($idc==$rs[$id_cat]){
			$tpl->assign("showmenucatselected")	;
		}
		$sql1="SELECT * FROM $cat WHERE active=1 AND parentid=$rs[$id_cat] ORDER BY thu_tu DESC, name ASC";
		$db1=$DB->query($sql1);
		while($rs1=mysql_fetch_array($db1)){
			$tpl->newBlock("showcatmenu1");
			if($idc==$rs1[$id_cat]){
				$tpl->assign("showmenucat1selected")	;
			}
			$tpl->assign("name1",$rs1['name']);
			$tpl->assign("link1",$rs1['url']);
			$tpl->assign("id_cat1",$rs1[$id_cat]);
			$sql2="SELECT * FROM $cat WHERE active=1 AND parentid=$rs1[$id_cat] ORDER BY thu_tu DESC, name ASC";
			$db2=$DB->query($sql2);
			while($rs2=mysql_fetch_array($db2)){
				$tpl->newBlock("showcatmenu2");
				$tpl->assign("name2",$rs2['name']);
				$tpl->assign("id_cat2",$rs2[$id_cat]);
				$tpl->assign("link2",$rs2['url']);
			}	
		}	
	}	
}


?>
